package com.fzshang.api.controller;


import com.fzshang.commen.bean.AttributeClassification;
import com.fzshang.commen.bean.layuiBean.ResultPage;
import com.fzshang.commen.bean.layuiBean.VoPage;
import com.fzshang.commen.controller.BaseController;
import com.fzshang.commen.entity.ApiResult;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 属性分类 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2020-02-24
 */
@Controller
@RequestMapping("admin/attributeClassification")
public class AttributeClassificationController extends BaseController {


    /**
     * @return 主页面
     */
    @RequestMapping(value = "attributeClassification.html")
    public String attributeClassification(){
        return "admin/attributeClassification/attributeClassification";
    }

    /**
     * @return 添加页面
     */
    @RequestMapping(value = "attributeClassification_add.html")
    public String attributeClassification_add(){
        return "admin/attributeClassification/attributeClassification_add";
    }

    /**
     * @param model
     * @param id
     * @return 编辑页面
     */
    @RequestMapping(value = "attributeClassification_edit.html")
    public String attributeClassification_edit(Model model, Long id){
        model.addAttribute("attributeClassification",attributeClassificationService.getById(id));
        return "admin/attributeClassification/attributeClassification_edit";
    }

    /**
     * @param voPage
     * @return 后台查询
     */
    @RequestMapping(value = "selectMyPage",method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<AttributeClassification> selectMyPage(VoPage voPage, AttributeClassification attributeClassification){
        return attributeClassificationService.selectMyPage(voPage,attributeClassification);
    }


    /**
     * @param attributeClassification
     * @return 添加和修改
     */
    @RequestMapping(value = "saveOrUpdateById")
    @ResponseBody
    public ApiResult saveOrUpdateById(@RequestBody AttributeClassification attributeClassification){
        attributeClassification.setCreateTime(System.currentTimeMillis());
        if(attributeClassificationService.saveOrUpdate(attributeClassification)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

    /**
     * @param id
     * @return 删除
     */
    @RequestMapping(value = "deleteById")
    @ResponseBody
    public ApiResult deleteById(Long id){
        if(attributeClassificationService.removeById(id)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

}
